<!--
 * @Descripttion: 
 * @Author: voanit
 * @Date: 2022-04-07 11:57:08
 * @LastEditors: voanit
 * @LastEditTime: 2022-04-07 17:44:24
-->
<template>
  <div class="user-info">
    =={{ userId }}
    <!-- 个人信息 -->
    <el-form label-width="220px">
      <!--手机 -->

      <el-form-item label="手机">
        <el-input v-model="userInfo.mobile" style="width: 220px" />
      </el-form-item>

      <!-- 工号 入职时间 -->

      <el-form-item label="入职时间">
        <el-date-picker
          v-model="userInfo.timeOfEntry"
          type="date"
          class="inputW"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <!-- 员工照片 -->

      <el-form-item label="员工头像">
        <!-- 放置上传图片 -->
        <!-- <img :src="userInfo.staffPhoto" /> -->
        <uploadImg ref="uploadImg"></uploadImg>
      </el-form-item>

      <!-- 保存个人信息 -->
      <el-form-item>
        <el-button type="primary" @click="save">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getUserDetailById } from "@/api/user";
import { saveUserDetailById } from "@/api/employees";
export default {
  data() {
    return {
      userId: this.$route.params.id,
      userInfo: {
        mobile: "",
        timeOfEntry: "",
      },
    };
  },
  created() {
    this.getInfo();
  },
  methods: {
    async getInfo() {
      const res = await getUserDetailById(this.$route.params.id);
      console.log(res, 9);
      this.userInfo = res.data;
      // 初次进入显示图片
      if (res.data.staffPhoto) {
        this.$refs.uploadImg.imageUrl = res.data.staffPhoto;
      }
    },
    async save() {
      // 保存更新
      const res = await saveUserDetailById({
        id: this.$route.params.id,
        ...this.userInfo,
        staffPhoto: this.$refs.uploadImg.imageUrl,
      });
      /* 更新页面 */
      this.$store.dispatch("user/getInfo");
      /* this.$refs.uploadImg====获取的是图片上传子组件就相当于子组件的this */
      // console.log(this.$refs.uploadImg.imageUrl, 77);
    },
  },
};
</script>

<style scoped lang="scss">
.user-info {
  padding-top: 20px;
}
</style>
